<%--
  Created by IntelliJ IDEA.
  User: limin
  Date: 2021/8/5
  Time: 14:54
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML>
<html>
<head>
    <base href="<%=basePath%>">

    <title></title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">

    <link rel="stylesheet" type="text/css" href="css/edittable.css"  >
    <link rel="stylesheet" type="text/css" href="css/validate.css"  >
    <script type="text/javascript"  src="js/jquery-1.8.0.js"></script>

    <script>
        $(function(){
            $("input[type=text],textarea").focus(function(){
                $(this).addClass("input_focus");
            }).blur(function(){
                $(this).removeClass("input_focus");
            });

            $(".form_btn").hover(function(){
                    $(this).css("color","red").css("background","#6FB2DB");
                },

                function(){
                    $(this).css("color","#295568").css("background","#BAD9E3");
                });
        });
        $(function(){
            $("#adminName").blur(function(){
                $.ajax({
                    type:"post",
                    url:"AdminServlet.do",
                    data:{
                        adminName:$("#adminName").val(),
                        flag:"checkAdminName"
                    },
                    success:function(data){
                        if(data == "1"){
                            if($("#adminName").val() == ""){
                                $("#adminName_msg").html("用户名不能为空")
                            }else{
                                $("#adminName_msg").html("用户名可用")
                            }
                        }else{
                            $("#adminName_msg").html("用户名已被使用")
                        }
                    },
                    error:function(){
                        alert("Error")
                    }
                })
            })
        })
    </script>
    <script>
        function checkAdminName(){
            var reg = /^[a-zA-z0-9]{4,15}$/
            if( reg.test( $("#adminName").val() ) ){
                return true;
            }
            return false;
        }

        function checkPassword(){
            var reg = /^[a-zA-Z0-9]{6,20}$/
            if( reg.test( $("#password").val() ) ){
                $("#password_msg").html("密码格式正确")
                return true;
            }
            $("#password_msg").html("密码格式错误")
            return false;
        }

        function checkPWDConfirm(){
            if($("#password").val() == $("#pwdconfirm").val()){
                $("#pwdconfirm_msg").html("两次密码一致")
                return true;
            }
            $("#pwdconfirm_msg").html("两次密码不一致")
            return false;
        }

        function check(){
            var result = true;
            if(checkAdminName()==false){
                result = false;
            }
            if(checkPassword()==false){
                result = false;
            }
            if(checkPWDConfirm()==false){
                result = false;
            }
            if(result == true){
                return confirm("确认提交吗");
            }
            return result;
        }
    </script>

</head>

<body>
<div class ="div_title">
    <div class="div_titlename"> <img src="images/san_jiao.gif" ><span>管理员添加</span></div>
</div>

<form action="AdminServlet.do?flag=add" method="post"  onsubmit="return check()">
    <table class="edit_table" >
        <tr>
            <td class="td_info">用户账号:</td>
            <td class="td_input_short">
                <input type="text" class="txtbox" id="adminName" name="adminName" />
            </td>
            <td>
                <label class="validate_info" id="adminName_msg">4-15位；只限数字(0-9)和英文(a-z),不区分大小写</label>
            </td>
        </tr>
        <tr>
            <td class="td_info">用户密码:</td>
            <td>
                <input type="text"  class="txtbox"  name="password"  id="password" />
            </td>
            <td><label  class="validate_info" id="password_msg" >数字或英文,6-20位</label></td>
        </tr>
        <tr>
            <td class="td_info">重复密码:</td>
            <td><input type="text" class="txtbox" id="pwdconfirm"  />
            </td>
            <td><label  class="validate_info"  id="pwdconfirm_msg">请重复输入密码</label></td>
        </tr>
        <tr>
            <td class="td_info">备注信息:</td>
            <td><textarea rows="4" cols="27" name="note" class="txtarea"></textarea> </td>
            <td><label></label></td>
        </tr>
        <tr>
            <td class="td_info"> </td>
            <td>
                <input class="form_btn" type="submit" value="提交" />
                <input type="reset"  class="form_btn" value="重置" />
            </td>
            <td>
                <label id="result_msg" class="result_msg"></label>
            </td>
        </tr>
    </table>
</form>
</body>
</html>

